import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm";

@Index("im_user_id", ["imUserId"], { unique: true })
@Index("phone", ["phone"], { unique: true })
@Entity("user", { schema: "chat" })
export class User {
  @PrimaryGeneratedColumn({ type: "int", name: "id", unsigned: true })
  id: number;

  @Column("varchar", {
    name: "im_user_id",
    unique: true,
    length: 15,
    default: () => "'用户id'",
  })
  imUserId: string;

  @Column("varchar", { name: "name", length: 50 })
  name: string;

  @Column("varchar", { name: "avatar", length: 100 })
  avatar: string;

  @Column("tinyint", {
    name: "gender",
    comment: "性别,1:男2女",
    unsigned: true,
    default: () => "'0'",
  })
  gender: number;

  @Column("char", { name: "phone", unique: true, length: 11 })
  phone: string;

  @Column("char", { name: "password", length: 64 })
  password: string;

  @Column("char", { name: "salt", length: 12 })
  salt: string;

  @Column("tinyint", {
    name: "at_im",
    comment: "是否已经注册到腾讯",
    unsigned: true,
    default: () => "'0'",
  })
  atIm: number;

  @Column("date", { name: "birth", nullable: true, comment: "生日" })
  birth: string | null;

  @Column("json", {
    name: "tags",
    nullable: true,
    comment: "个人标签（JSON 数组）",
  })
  tags: string[] | null;

  @Column("varchar", {
    name: "sign",
    nullable: true,
    comment: "个性签名",
    length: 255,
  })
  sign: string | null;

  @Column("int", {
    name: "register_time",
    unsigned: true,
    default: () => "'0'",
  })
  registerTime: number;

  @Column("int", {
    name: "last_login_time",
    unsigned: true,
    default: () => "'0'",
  })
  lastLoginTime: number;

  @Column("boolean", { name: "official" })
  official: boolean;
}
